package com.controller;

import com.base.BaseController;
import com.base.BasePageReq;
import com.base.BasePageRes;
import com.req.ArticalCommentPageReq;
import com.req.ArticalCommentReq;
import com.res.ArticalCommentRes;
import com.res.UserRes;
import com.service.ArticalCommentService;
import com.util.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/artical/comment")
@Api(tags = "帖子评论")
public class ArticalCommentController extends BaseController {
    @Autowired
    private ArticalCommentService articalCommentService;
    @PostMapping("/save")
    @ApiOperation("评论的增删改查")
    public R<ArticalCommentRes> saveArtical(@RequestBody ArticalCommentReq req){
        UserRes user = this.getUser();
        req.setSendUser(user.getId());
        return R.ok(articalCommentService.saveComment(req));
    }

    /**
     * 这个适合人的接口，不适合首页的展示接口。
     * @param pageReq
     * @return
     */
    @PostMapping("/queryPage")
    @ApiOperation("评论分页查询")
    public R<BasePageRes> queryPage(@RequestBody ArticalCommentPageReq pageReq){
        return R.ok(articalCommentService.queryPage(pageReq,null));
    }
}
